
import { _decorator, Component, Node, Vec2 } from 'cc';
import { EventLister } from './EventLister';
import { EventProtoCtrl } from './EventProtoCtrl';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = TouchCtrl
 * DateTime = Sat Feb 24 2024 16:02:58 GMT+0800 (中国标准时间)
 * Author = heyongtao
 * FileBasename = TouchCtrl.ts
 * FileBasenameNoExtension = TouchCtrl
 * URL = db://assets/scripts/utils/TouchCtrl.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('TouchCtrl')
export class TouchCtrl extends Component {

    public m_isTouch = false;
    public m_touchState = 0; // 0 停止，1 开始，2 移动
    public m_curTouchPoint:Vec2 = new Vec2(0,0);
    private static ince:TouchCtrl;

    public static GetInstance(): TouchCtrl{
        if(this.ince == undefined){
            this.ince = new TouchCtrl();
        }
        return this.ince;
    }

    protected onLoad(): void {
        let self = this;
        this.node.on(Node.EventType.TOUCH_END,(msg:any)=>{
            let touchPoint = msg.touch.getLocation();
            this.m_isTouch = false;
            this.m_touchState = 0;
            console.log("touch end")
        },this);
        this.node.on(Node.EventType.TOUCH_START,(msg:any)=>{
            let touchPoint:Vec2 = msg.touch.getLocation();
            this.m_isTouch = true;
            this.m_touchState = 1;
            this.m_curTouchPoint = touchPoint;
            //EventLister.GetInstance().Emit(EventProtoCtrl.EV_PROTOCTRL_TOUCH,touchPoint)
            console.log("touch start")
        },this);
        // this.node.on(Node.EventType.TOUCH_MOVE,(msg:any)=>{
        //     let touchPoint = msg.touch.getLocation();
        //     this.m_isTouch = true;
        //     this.m_touchState = 2;
        //     this.m_curTouchPoint = touchPoint;
        //     console.log("touch move")
        // },this)
    }

    start () {
        // [3]
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
